SQL Antipatterns (for Amanda Dunlap) by Bill Karwin

SQL Antipatterns (for Amanda Dunlap) by Bill Karwin

Author:Bill Karwin
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
ISBN: 1-934356-55-7
Publisher: The Pragmatic Bookshelf, LLC (212800)


SELECT * FROM Bugs WHERE assigned_to <> NULL;

The condition in a WHERE clause is satisfied only when the expression is true, but a comparison to NULL is never true; it’s unknown. It doesn’t matter whether the comparison is for equality or inequality; it’s still unknown, which is certainly not true. Neither of the previous queries return rows where assigned_to is null.

Using Null in Query Parameters

It’s also difficult to use null in a parameterized SQL expression as if the null were an ordinary value.

Fear-Unknown/anti/parameter.sql

SELECT * FROM Bugs WHERE assigned_to = ?;

The previous query returns predictable results when you send an ordinary integer value for the parameter, but you can’t use a literal NULL as the parameter.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.